package com.personal.system.controller.act;

import java.util.List;

import com.personal.common.result.Result;
import com.personal.system.service.act.WorkflowExampleService;
import com.personal.system.entity.WorkflowExample;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 工作流实例Controller
 */
@RestController
@RequestMapping("/example")
public class WorkflowExampleController {

    @Resource
    private WorkflowExampleService workflowExampleService;

    @GetMapping("/list")
    public Result list() {
        List<WorkflowExample> list = workflowExampleService.selectWorkflowExampleList(null);

        return Result.ok(list);
    }


    /**
     * 导出工作流实例列表
     */
    @GetMapping("/export")
    public Result export(WorkflowExample workflowExample) {
        List<WorkflowExample> list = workflowExampleService.selectWorkflowExampleList(workflowExample);

        return Result.ok(list);
    }

    /**
     * 获取工作流实例详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:example:query')")
    @GetMapping(value = "/{id}")
    public Result getInfo(@PathVariable("id") String id) {
        return Result.ok(workflowExampleService.selectWorkflowExampleById(id));
    }

    /**
     * 新增工作流实例
     */
    @PostMapping
    public Result add(@RequestBody WorkflowExample workflowExample) {
        return Result.ok(workflowExampleService.insertWorkflowExample(workflowExample));
    }

    /**
     * 修改工作流实例
     */
    @PutMapping
    public Result edit(@RequestBody WorkflowExample workflowExample) {
        return Result.ok(workflowExampleService.updateWorkflowExample(workflowExample));
    }

    /**
     * 删除工作流实例
     */
    @DeleteMapping("/{ids}")
    public Result remove(@PathVariable String[] ids) {
        return Result.ok(workflowExampleService.deleteWorkflowExampleByIds(ids));
    }
}
